{include file="public/header" /}
<style type="text/css">
/* TAB */
.nav-tabs.nav>li>a {
    padding: 10px 25px;
    margin-right: 0;
}
.nav-tabs.nav>li>a:hover,
.nav-tabs.nav>li.active>a {
    border-top: 3px solid #1ab394;
    padding-top: 8px;
}
.nav-tabs>li>a {
    color: #A7B1C2;
    font-weight: 500;  
    margin-right: 2px;
    line-height: 1.42857143;
    border: 1px solid transparent;
    border-radius: 0;
}
</style>

<body class="gray-bg">
<div class="wrapper wrapper-content animated">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>自动回复</h5>
                </div>
                <div class="ibox-content">           
                    <div class="panel-body">
                        <div class="builder-tabs builder-form-tabs">
                            <ul class="nav nav-tabs">
                                <li ><a href="{:url('autoreply')}">自定义回复</a></li>
                                <li ><a href="{:url('autoreplyadd')}">添加自定义回复</a></li>
                                <li class="active"><a href="#">编辑自定义回复</a></li>
                            </ul>
                        </div>
                        <div class="form-group"></div>
                        <div class="row">
                            <div class="col-xs-12">
                                <form id="autoreplyadd" action="{:url('autoreplyeditor')}" method="post" class="form-horizontal">
                                    <div class="hr-line-dashed"></div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">规则名称：</label>
                                        <div class="input-group col-sm-4">
                                            <input id="name" type="text" class="form-control" name="name" value="{$data.name}">
                                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 规则的描述信息</span>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">关键词：</label>
                                        <div class="input-group col-sm-4">
                                            <input id="keywords" type="text" class="form-control" name="keywords" value="{$data.keywords}">
                                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>要触发的关键词,多个(,)逗号隔开</span>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">回复内容：</label>
                                        <div class="input-group col-sm-4">
                                            <textarea class="form-control" id="reply" type="text" rows="4" name="reply">{$data.reply}</textarea>
                                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 要自动回复对应关键词的内容</span>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                    </div>
                                    <div class="hr-line-dashed"></div>
                                    <input type="hidden" name="id" value="{$data.id}">
                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-3">
                                            <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存信息</button>&nbsp;&nbsp;&nbsp;
                                            <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                                        </div>
                                    </div>
                                </form>

                             </div>
                        </div>

                </div>
				</div>

                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}

<script type="text/javascript">

    $(function() {
        $('#autoreplyadd').ajaxForm({
            beforeSubmit: checkForm,
            success: complete,
            dataType: 'json'
        });

        function checkForm() {
            if ('' == $.trim($('#name').val())) {
                layer.msg('规则名称不能为空', {icon: 2, time: 1500, shade: 0.1}, function (index) {
                    layer.close(index);
                });
                return false;
            }

            if ('' == $.trim($('#keywords').val())) {
                layer.msg('关键词不能为空', {icon: 2, time: 1500, shade: 0.1}, function (index) {
                    layer.close(index);
                });
                return false;
            }

            if ('' == $.trim($('#reply').val())) {
                layer.msg('回内容不能为空', {icon: 2, time: 1500, shade: 0.1}, function (index) {
                    layer.close(index);
                });
                return false;
            }



        }


        function complete(data) {
            if (data.code == 1) {
                layer.msg(data.msg, {icon: 6, time: 1500, shade: 0.1}, function (index) {
                     window.location.href="{:url('autoreply')}";
                    //window.location.reload(true);
                });
            } else {
                layer.msg(data.msg, {icon: 5, time: 1500, shade: 0.1});
                return false;
            }
        }
    })

</script>
</body>
</html>
